﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Estsh.Core.Base;
using Estsh.Core.Wms.IRepositories;
using Estsh.Core.Wms.IServices;
using Estsh.Core.Model.Result;
using Estsh.Core.Services;
using Estsh.Core.Repositories;
using Estsh.Core.Models;
using Estsh.Core.Model.Extend.Models;
using Newtonsoft.Json.Linq;
using static Estsh.Core.Model.EnumUtil.WmsEnumUtil;
using Estsh.Core.Model.EnumUtil;
using Estsh.Core.Model.Extend;
using SqlSugar;
using Estsh.Core.Wms.Repositories;
using NPOI.Util;

namespace Estsh.Core.Wms.Services
{
    public class MoveService : BaseService<BaseEntity>, IMoveService
    {
        private readonly IMoveRepository repository;
        public MoveService(IMoveRepository _repository) : base(_repository)
        {
            repository = _repository;
        }

        /// <summary>
        /// 获取周转箱信息
        /// </summary>
        /// <param name="loginId"></param>
        /// <param name="rackNo"></param>
        /// <param name="isHandover"></param>
        /// <returns></returns>
        public SetObjectDetail CheckContainer(string loginId, string rackNo, string isHandover)
        {
            SetObjectDetail rfInfo = new SetObjectDetail();
            //验证扫描的是周转箱还是托
            WmsRack_Extend rackInfo = repository.GetRackInfo(rackNo);
            if (rackInfo == null)
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "[" + rackNo + "]:周转箱不存在，请检查!";
                return rfInfo;
            }
            List<WmsRackPackage_Extend> rackPackageInfo = repository.GetRackPackageInfo(rackNo);

            //根据周转箱号去条码表找对应的信息
            SysStock cartonInfo = repository.CheckCartonNoStatus(rackInfo.RackNo);

            if (cartonInfo == null)
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "[" + rackNo + "]:周转箱在条码表中不存在，请检查!";
                return rfInfo;
            }
            rfInfo.type = "PASS";
            rfInfo.message = "操作成功!请扫描箱条码或周转箱";
            rfInfo.wmsObjectDetail = rackPackageInfo.ConvertAll(s => (object)s);
            return rfInfo;  //"OK" + cartonInfo.LocateName;
        }


        /// <summary>
        /// 扫描箱条码
        /// </summary>
        /// <param name="loginId"></param>
        /// <param name="cartonNo"></param>
        /// <param name="locateName"></param>
        /// <param name="isHandover"></param>
        /// <param name="rackNo"></param>
        /// <returns></returns>
        public SetObjectDetail CheckBarcode(string loginId, string cartonNo, string locateName, string isHandover, string rackNo)
        {
            SetObjectDetail rfInfo = new SetObjectDetail();
            if (cartonNo == rackNo)
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "[" + cartonNo + "]:不能扫描同级别周转箱，请检查!";
                return rfInfo;
            }

            SysStock stockInfo = repository.GetStockCartonInfo(cartonNo);
            if (stockInfo != null && stockInfo.CartonType == 1)
            {
                //获取周转箱中的物料
                List<WmsRackPackage_Extend> rackPackageInfo = repository.GetCartonInfo(cartonNo);

                if (rackPackageInfo.Count > 0)
                {
                    rfInfo.type = "PASS";
                    rfInfo.message = "操作成功!请选择物料输入拆分数量";
                    rfInfo.wmsObjectDetail = rackPackageInfo.ConvertAll(s => (object)s);
                }
                else
                {
                    rfInfo.type = "FAIL";
                    rfInfo.message = "未查询到数据，请检查！";
                }
            }
            else
            {
                //获取扫描的箱条码
                SysStock_Extend stockInfo2 = repository.GetCartonNoInfo2(cartonNo);
                if (stockInfo2 == null)
                {
                    rfInfo.type = "FAIL";
                    rfInfo.message = "扫描的箱条码不存在，请检查！";
                    return rfInfo;
                }
                else
                {
                    //判断箱条码是否可用
                    SysStock cartonInfo = repository.CheckCartonNoStatus(cartonNo); //获取箱条码信息
                    if (cartonInfo == null)
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "[" + cartonNo + "]:条码不可用，请检查!";
                        return rfInfo;
                    }
                    if (cartonInfo.Enabled.Equals("N"))
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "[" + cartonNo + "]:箱条码已冻结，无法操作!";
                        return rfInfo;
                    }
                    if (cartonInfo.Status != (int)StockStatus.INSTOCKED)
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "[" + cartonNo + "]:该条码为" + cartonInfo.StockStatus + "状态，请检查!";
                        return rfInfo;
                    }
                    rfInfo.type = "PASS";
                    rfInfo.message = "请输入需要拆分的数量！";
                    rfInfo.wmsObjectDetail = null;
                    return rfInfo;
                }
            }
            return rfInfo;
        }


        /// <summary>
        /// 执行移库
        /// </summary>
        /// <param name="user">用户名</param>
        /// <returns></returns>
        public string CheckMove(string loginId, string cartonNo, string locateName, string isPack)
        {
            //List<SysStock> cartInfos =new List<SysStock>();
            //判断箱条码是否可用
            SysStock cartonInfo = repository.CheckCartonNoStatus(cartonNo);
            string strcartNo = "" + cartonNo + "','";


            if (cartonInfo == null)
            {
                return "[" + cartonNo + "]:条码不可用，请检查!";
            }
            if (cartonInfo.Enabled.Equals("N"))
            {
                return "[" + cartonNo + "]:箱条码已冻结，无法操作!";
            }
            if (cartonInfo.Status != (int)StockStatus.INSTOCKED)
            {
                return "[" + cartonNo + "]:该条码为" + cartonInfo.StockStatus + "状态，请检查!";
            }

            //获取库位表库位与绑定零件信息
            List<SysLocate> sysLocates = repository.CheckLocateStatus(locateName);
            if (sysLocates.Count == 0)
            {
                return "[" + locateName + "]:库位不存在，请检查!";
            }

            if (cartonInfo.ErpWarehouse != sysLocates[0].ErpWarehouse)
            {
                return "移库不允许跨库存地!";
            }
            if (sysLocates[0].LocateId == cartonInfo.LocateId)
            {
                return "[" + locateName + "]:来源库位与目标库位一致，请检查!";
            }
            //扫描的是周装箱
            if (cartonInfo.CartonType == 1)
            {
                //获取周转箱信息
                WmsRack rackInfo = repository.GetRackInfo(cartonNo);
                if (rackInfo == null)
                {
                    return "[" + cartonNo + "]:周转箱不存在!";
                }

                List<WmsRackPackage_Extend> packagelist = repository.GetCartonInfo(cartonNo);
                for (int i = 0; i < packagelist.Count; i++)
                {
                    strcartNo += packagelist[i].CortonNo + "','";
                }
                if (strcartNo.EndsWith("'"))
                    strcartNo = strcartNo.Substring(0, strcartNo.Length - 3);
            }
            else
            {
                if (strcartNo.EndsWith("'"))
                    strcartNo = strcartNo.Substring(0, strcartNo.Length - 3);
            }




            List<SysStock> UseStocks = repository.CheckUseStockCapacity(locateName); //当前库位已经使用库存列表
            decimal QtySum = UseStocks.Sum(a => a.Qty);//已经使用库存总量

            if (isPack == "True")
            {
                //组托入库
                List<SysStock_Extend> stocksByPack = repository.CheckCartonNoStatusByPack(cartonNo);

                decimal QtySumByPack = stocksByPack.Sum(a => a.Qty);//组托入库所需库容
                if (sysLocates[0].LocateCapacity > QtySum + QtySumByPack)
                {
                    //有库容
                    //判断入库库位类型 是单零件 还是多零件
                    var getcount = stocksByPack.GroupBy(a => a.PartId).Select(b => (new SysStock
                    {
                        PartId = b.Key,
                        Qty = b.Count()
                    }));
                    int PartCount = getcount.Count();
                    if (PartCount > 1)
                    {
                        if (sysLocates[0].LocateType == (int)WmsEnumUtil.LocateType.BASICS_LOCATE)
                        {
                            return "库位[" + locateName + "]类型无法满足操作，请更换为动态组合库！";
                        }
                        if (sysLocates[0].LocateType == (int)WmsEnumUtil.LocateType.MANEUVER_LOCATE)
                        {
                            return "库位[" + locateName + "]类型无法满足操作，请更换为动态组合库！";
                        }
                        //多种类，进动态组合库 (int)WmsEnumUtil.LocateType.COMBINATION_LOCATE 30
                        if (sysLocates[0].LocateType == (int)WmsEnumUtil.LocateType.COMBINATION_LOCATE)
                        {
                            //动态组合库库位正确 ，有库容，正常入库
                            return repository.UpdateStockStatus(stocksByPack, sysLocates, (int)WmsEnumUtil.StockStatus.INSTOCKED, (int)WmsEnumUtil.TransType.MOVESTOCK, loginId);
                        }
                    }
                    else
                    {
                        //单种类，进基础库位 、 机动库位  (int)WmsEnumUtil.LocateType
                        if (sysLocates[0].LocateType == (int)WmsEnumUtil.LocateType.BASICS_LOCATE || sysLocates[0].LocateType == (int)WmsEnumUtil.LocateType.LINE_LOCATE)
                        {
                            if (string.IsNullOrEmpty(sysLocates[0].PartNo))
                            {
                                int Outstatus = (int)WmsEnumUtil.StockStatus.INSTOCKED;
                                //基础库位正确 ，有库容，正常入库
                                if (sysLocates[0].LocateType == (int)WmsEnumUtil.LocateType.LINE_LOCATE)
                                {
                                    Outstatus = (int)WmsEnumUtil.StockStatus.ONLINED;
                                }
                                return repository.UpdateStockStatus(stocksByPack, sysLocates, Outstatus, (int)WmsEnumUtil.TransType.MOVESTOCK, loginId);
                            }
                            else
                            {
                                // TODO 此处需要重新梳理逻辑 
                                if (sysLocates.Where(a => a.PartId == cartonInfo.PartId).Count() >= 0)
                                {
                                    int Outstatus = (int)WmsEnumUtil.StockStatus.INSTOCKED;
                                    //基础库位正确 ，有库容，正常入库
                                    if (sysLocates[0].LocateType == (int)WmsEnumUtil.LocateType.LINE_LOCATE)
                                    {
                                        Outstatus = (int)WmsEnumUtil.StockStatus.ONLINED;
                                    }
                                    return repository.UpdateStockStatus(stocksByPack, sysLocates, Outstatus, (int)WmsEnumUtil.TransType.MOVESTOCK, loginId);
                                }
                                else
                                {
                                    return "库位[" + locateName + "]与条码零件[" + cartonInfo.PartNo + "]不匹配！";
                                }
                            }

                        }
                        if (sysLocates[0].LocateType == (int)WmsEnumUtil.LocateType.MANEUVER_LOCATE)
                        {
                            //机动库位正确 ，有库容，正常入库
                            if (UseStocks.Where(a => a.PartId == cartonInfo.PartId).Count() >= 0)
                            {
                                //基础库位正确 ，有库容，正常入库
                                return repository.UpdateStockStatus(stocksByPack, sysLocates, (int)WmsEnumUtil.StockStatus.INSTOCKED, (int)WmsEnumUtil.TransType.MOVESTOCK, loginId);
                            }
                            else
                            {
                                return "库位[" + locateName + "]与条码零件[" + cartonInfo.PartNo + "]不匹配！";
                            }
                        }
                        //多种类，进动态组合库 (int)WmsEnumUtil.LocateType.COMBINATION_LOCATE 30
                        if (sysLocates[0].LocateType == (int)WmsEnumUtil.LocateType.COMBINATION_LOCATE)
                        {
                            //动态组合库库位正确 ，有库容，正常入库
                            return repository.UpdateStockStatus(stocksByPack, sysLocates, (int)WmsEnumUtil.StockStatus.INSTOCKED, (int)WmsEnumUtil.TransType.MOVESTOCK, loginId);
                        }
                    }
                    return "[" + locateName + "]:库位类型不匹配，请检查！";
                }
                else
                {
                    return "[" + locateName + "]:库位容量不足，请检查！";
                }
            }
            else
            {
                //for (int i = 0; i < cartInfos.Count; i++)
                //{
                //string cartno = cartInfos[i].CartonNo;
                //单包装入库
                List<SysStock_Extend> sysStock = repository.CheckCartonNolist(strcartNo);

                if (sysLocates[0].LocateCapacity > QtySum + sysStock[0].Qty)
                {
                    //有库容
                    if (sysLocates[0].LocateType == (int)WmsEnumUtil.LocateType.BASICS_LOCATE || sysLocates[0].LocateType == (int)WmsEnumUtil.LocateType.LINE_LOCATE)
                    {
                        // TODO 此处需要重新写逻辑
                        if (sysLocates.Where(a => a.PartId == cartonInfo.PartId).Count() > 0)
                        {
                            int Outstatus = cartonInfo.Status;
                            //基础库位正确 ，有库容，正常入库
                            if (sysLocates[0].LocateType == (int)WmsEnumUtil.LocateType.LINE_LOCATE)
                            {
                                //Outstatus = (int)WmsEnumUtil.StockStatus.ONLINED;
                                Outstatus = cartonInfo.Status;
                            }
                            //基础库位正确 ，有库容，正常入库
                            List<SysStock_Extend> sysStocks = new List<SysStock_Extend>();
                            sysStock.ForEach(item =>
                            {
                                sysStocks.Add(item);
                            });
                            //sysStocks.Add(sysStock);
                            return repository.UpdateStockStatus(sysStocks, sysLocates, Outstatus, (int)WmsEnumUtil.TransType.MOVESTOCK, loginId);
                        }
                        else
                        {
                            return "库位[" + locateName + "]与条码零件[" + cartonInfo.PartNo + "]不匹配！";
                        }
                    }
                    if (sysLocates[0].LocateType == (int)WmsEnumUtil.LocateType.MANEUVER_LOCATE)
                    {
                        //机动库位正确 ，有库容，正常入库
                        if (UseStocks.Where(a => a.PartId == cartonInfo.PartId).Count() >= 0)
                        {
                            //基础库位正确 ，有库容，正常入库
                            List<SysStock_Extend> sysStocks = new List<SysStock_Extend>();
                            //sysStocks.Add(sysStock);
                            sysStock.ForEach(item =>
                            {
                                sysStocks.Add(item);
                            });
                            return repository.UpdateStockStatus(sysStocks, sysLocates, (int)WmsEnumUtil.StockStatus.INSTOCKED, (int)WmsEnumUtil.TransType.MOVESTOCK, loginId);
                        }
                        else
                        {
                            return "库位[" + locateName + "]与条码零件[" + cartonInfo.PartNo + "]不匹配！";
                        }
                    }
                    if (sysLocates[0].LocateType == (int)WmsEnumUtil.LocateType.COMBINATION_LOCATE)
                    {
                        //动态组合库库位正确 ，有库容，正常入库
                        List<SysStock_Extend> sysStocks = new List<SysStock_Extend>();
                        //sysStocks.Add(sysStock);
                        sysStock.ForEach(item =>
                        {
                            sysStocks.Add(item);
                        });
                        return repository.UpdateStockStatus(sysStocks, sysLocates, (int)WmsEnumUtil.StockStatus.INSTOCKED, (int)WmsEnumUtil.TransType.MOVESTOCK, loginId);
                    }
                    return "[" + locateName + "]:库位类型异常，请检查！";
                }
                else
                {
                    return "[" + locateName + "]:库位容量不足，请检查！";
                }
                //}            
            }

            //return "OK";
        }

        //判断库位
        public string CheckLocateName(string loginId, string LocateName, string isPack)
        {
            List<SysLocate> sysLocates = repository.CheckLocateStatus(LocateName);
            if (sysLocates.Count == 0)
            {
                return "[" + LocateName + "]:库位不存在，请检查!";
            }

            List<SysStock> sysStocks = repository.CheckUseStockCapacity(LocateName);
            if (sysStocks.Count == 0)
            {
                return "OK";
            }
            if (sysStocks[0].LocateNum > sysLocates[0].LocateCapacity)
            {
                return "[" + LocateName + "]:库位容量已满，请检查！";
            }


            return "OK";
        }

        //获取信息列表
        public List<SysStock> GetMovePartInfo(string cartonNo, string isPack)
        {
            if (isPack == "True")
            {
                //组托移
                return repository.GetCartonNoInfoByPack(cartonNo);
            }
            else
            {
                //单包装移
                return repository.GetCartonNoInfo(cartonNo);
            }
        }


        public List<WmsRackPackage_Extend> GetCheckCartNoInfo(string rackNo)
        {
            return repository.GetCartonInfo(rackNo);

        }


        /// <summary>
        /// 获取单据移动单列表
        /// </summary>
        /// <returns></returns>
        public List<WmsMoveHeader> GetMoveOrderList(string cartonno)
        {
            return repository.GetMoveOrderList(cartonno);
        }

        /// <summary>
        /// 获取单据移动单列表
        /// </summary>
        /// <returns></returns>
        public List<WmsMoveDetail> GetMoveOrderDetailList(string orderNo)
        {
            return repository.CheckMoveOrderLocate(orderNo);
        }

        public List<WmsRackPackage_Extend> GetRackPartNo(string rackNo)
        {
            return repository.GetRackPartNo(rackNo);
        }

        /// <summary>
        /// 单据移动单 库位判断
        /// </summary>
        /// <param name="loginId"></param>
        /// <param name="LocateName"></param>
        /// <param name="isPack"></param>
        /// <returns></returns>
        public string CheckMoveOrderLocateName(string loginId, string LocateName, string orderNo)
        {
            List<WmsMoveDetail> wmsMoveDetails = repository.CheckMoveOrderLocate(orderNo);

            if (wmsMoveDetails.Count == 0)
            {
                return "[" + orderNo + "]:订单明细不存在，请检查!";
            }
            string dest_zone = wmsMoveDetails[0].DestZoneId.ToString();

            List<SysLocate> sysLocates = repository.CheckLocateStatus(LocateName);

            if (sysLocates.Count == 0)
            {
                return "[" + LocateName + "]:库位不存在，请检查!";
            }

            ///大于1 ，说明移动单订单中设置了移动目的地库区，判断扫描的库位是否是指定库区
            if (dest_zone.Length > 1)
            {
                if (sysLocates[0].ZoneId.ToString() == dest_zone)
                {
                    //扫描库位在订单要求库区中
                }
                else
                {
                    return "[" + LocateName + "]:库位不在订单库区中，请检查!";
                }
            }

            List<SysStock> sysStocks = repository.CheckUseStockCapacity(LocateName);
            if (sysStocks.Count == 0)
            {
                return "OK";
            }
            if (sysStocks[0].LocateNum > sysLocates[0].LocateCapacity)
            {
                return "[" + LocateName + "]:库位容量已满，请检查！";
            }


            return "OK";
        }

        /// <summary>
        /// 单据移动单 箱条码判断
        /// </summary>
        /// <param name="loginId"></param>
        /// <param name="cartonNo"></param>
        /// <param name="locateName"></param>
        /// <returns></returns>
        public string CheckCartonMoveOrder(string loginId, string cartonNo, string locateName, string orderNo)
        {
            //判断箱条码来源是否满足订单
            List<WmsMoveDetail> wmsMoveDetails = repository.CheckMoveOrderLocate(orderNo);

            if (wmsMoveDetails.Count == 0)
            {
                return "[" + orderNo + "]:订单明细不存在，请检查!";
            }
            string scr_zone = wmsMoveDetails[0].SrcZoneId.ToString();

            //判断箱条码是否可用
            SysStock cartonInfo = repository.CheckCartonNoStatus(cartonNo);

            List<WmsMoveDetail> ifnum = wmsMoveDetails.Where(a => a.PartId == cartonInfo.PartId).ToList();
            decimal partno = 0;
            if (ifnum.Count > 0)
            {
                if (ifnum[0].Qty == ifnum[0].OutQty)
                {
                    return "[" + cartonNo + "]:箱条码零件在订单中已完成操作，请检查!";
                }
            }
            else
            {
                return "[" + cartonNo + "]:箱条码零件不在订单明细中，请检查!";
            }

            if (scr_zone.Length > 1 && cartonInfo != null)
            {
                if (cartonInfo.ZoneId.ToString() != scr_zone)
                {
                    return "[" + cartonNo + "]:箱条码不在订单要求来源的库区，请检查!";
                }
            }
            if (cartonInfo == null)
            {
                return "[" + cartonNo + "]:条码不存在，请检查!";
            }
            if (cartonInfo.Enabled.Equals("N"))
            {
                return "[" + cartonNo + "]:箱条码已冻结，无法操作!";
            }
            if (cartonInfo.Status != (int)StockStatus.INSTOCKED)
            {
                return "[" + cartonNo + "]:该条码为" + cartonInfo.StockStatus + "状态，请检查!";
            }




            //获取库位表库位与绑定零件信息
            List<SysLocate> sysLocates = repository.CheckLocateStatus(locateName);
            if (sysLocates.Count == 0)
            {
                return "[" + locateName + "]:该库位不存在，请检查!";
            }
            if (sysLocates[0].LocateId == cartonInfo.LocateId)
            {
                return "[" + locateName + "]:来源库位与目标库位一致，请检查!";
            }



            List<SysStock> UseStocks = repository.CheckUseStockCapacity(locateName); //当前库位已经使用库存列表
            decimal QtySum = UseStocks.Sum(a => a.Qty);//已经使用库存总量

            SysStock sysStock = repository.CheckCartonNoStatus(cartonNo);
            if (sysLocates[0].LocateCapacity > QtySum + sysStock.Qty)
            {
                //有库容
                if (sysLocates[0].LocateType == (int)WmsEnumUtil.LocateType.BASICS_LOCATE)
                {
                    // TODO 此处需要重新写逻辑
                    if (sysLocates.Where(a => a.PartId == cartonInfo.PartId).Count() > 0)
                    {
                        //基础库位正确 ，有库容，正常入库
                        List<SysStock> sysStocks = new List<SysStock>();
                        sysStocks.Add(sysStock);
                        return repository.UpdateStockStatusByMoveOrder(sysStocks, sysLocates, (int)WmsEnumUtil.StockStatus.INSTOCKED, (int)WmsEnumUtil.TransType.MOVESTOCK, loginId, orderNo);
                    }
                    else
                    {
                        return "库位[" + locateName + "]与条码零件[" + cartonInfo.PartNo + "]不匹配！";
                    }
                }
                if (sysLocates[0].LocateType == (int)WmsEnumUtil.LocateType.MANEUVER_LOCATE)
                {
                    //机动库位正确 ，有库容，正常入库
                    if (UseStocks.Where(a => a.PartId == cartonInfo.PartId).Count() >= 0)
                    {
                        //基础库位正确 ，有库容，正常入库
                        List<SysStock> sysStocks = new List<SysStock>();
                        sysStocks.Add(sysStock);
                        return repository.UpdateStockStatusByMoveOrder(sysStocks, sysLocates, (int)WmsEnumUtil.StockStatus.INSTOCKED, (int)WmsEnumUtil.TransType.MOVESTOCK, loginId, orderNo);
                    }
                    else
                    {
                        return "库位[" + locateName + "]与条码零件[" + cartonInfo.PartNo + "]不匹配！";
                    }
                }
                if (sysLocates[0].LocateType == (int)WmsEnumUtil.LocateType.COMBINATION_LOCATE)
                {
                    //动态组合库库位正确 ，有库容，正常入库
                    List<SysStock> sysStocks = new List<SysStock>();
                    sysStocks.Add(sysStock);
                    return repository.UpdateStockStatusByMoveOrder(sysStocks, sysLocates, (int)WmsEnumUtil.StockStatus.INSTOCKED, (int)WmsEnumUtil.TransType.MOVESTOCK, loginId, orderNo);
                }
                return "[" + locateName + "]:库位类型异常，请检查！";
            }
            else
            {
                return "[" + locateName + "]:库位容量不足，请检查！";
            }
        }

        public string ChangeMoveHeaderStatus(string loginId, string orderNo)
        {
            List<WmsMoveDetail> wmsMoveDetails = repository.CheckMoveOrderLocate(orderNo);

            int statusSum = wmsMoveDetails.Sum(a => a.ItemStatus);

            if (wmsMoveDetails.Count * (int)WmsEnumUtil.MoveOrderStatus.COMPLETED == statusSum)
            {
                repository.ChangeMoveHeaderStatus(loginId, orderNo);
            }

            return "OK";
        }


        /// <summary>
        /// 移库单配料（不拆箱）-扫描箱条码或周转箱
        /// </summary>
        /// <param name="cartonNo"></param>
        /// <param name="orderNo"></param>
        /// <param name="isSplit"></param>
        /// <param name="loginId"></param>
        /// <returns></returns>
        public SetObjectDetail CheckCartonOrRack(string cartonNo, string orderNo, string isSplit, string loginId)
        {
            string rackNo = "";
            string SplitQty = "";
            string rackOrCartNo = "";
            SetObjectDetail rfInfo = new SetObjectDetail();//返回消息

            if (isSplit == "False")
            {
                //获取单据中的物料信息
                List<WmsMoveDetail_Extend> detailInfo = repository.GetMoveDetailInfo(orderNo);

                //判断扫描的是周转箱还是箱条码
                SysStock stockInfo = repository.GetStockCartonInfo(cartonNo);

                if (stockInfo != null && stockInfo.CartonType == 1)
                {
                    //获取周转箱中的物料
                    List<WmsRackPackage_Extend> rackPackageInfo = repository.GetCartonInfo(cartonNo);
                    int rackNum = 0;
                    List<WmsRackPackage_Extend> packagelist = null;
                    //判断周转箱内物料是否和单据物料一致
                    for (int i = 0; i < detailInfo.Count; i++)
                    {
                        packagelist = rackPackageInfo.Where(x => x.PartNo == detailInfo[i].PartNo).ToList();
                        if (packagelist.Count == 0)
                        {
                            rfInfo.type = "FAIL";
                            rfInfo.message = "周转箱内物料与单据物料不一致，请打开拆箱按钮后再操作！";
                            return rfInfo;
                        }
                    }
                    rackPackageInfo.ForEach(x =>
                    {
                        rackNum = rackNum + Convert.ToInt32(x.RackNum);
                    });

                    List<WmsMoveDetail_Extend> detaillist = detailInfo.Where(x => x.PartNo == stockInfo.PartNo).ToList();
                    if (detaillist.Count != 0)
                    {
                        decimal pickQty = detaillist.FirstOrDefault().PickQty;
                        decimal Qty = detaillist.FirstOrDefault().Qty;
                        decimal residueQtyf = Qty - pickQty;

                        if (pickQty >= Qty)
                        {
                            rfInfo.type = "FAIL";
                            rfInfo.message = "单据内配料数量已超出物料数量，请检查！";
                            return rfInfo;
                        }
                        if (detaillist.FirstOrDefault().Qty > residueQtyf)
                        {
                            rfInfo.type = "FAIL";
                            rfInfo.message = "扫描数量大于剩余配料数量，请检查！";
                            return rfInfo;
                        }
                    }



                    //判断是否存在在途库位
                    SysLocate locateInfo = repository.GetLocateZTbin();
                    if (locateInfo == null)
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "条码对应的库存地下没有在途库位，请检查！";
                        return rfInfo;
                    }
                    SplitQty = rackNum.ToString();
                    //一致将库位改变成在途
                    return repository.UpdteStatusBatach(locateInfo.LocateId, locateInfo.LocateName, orderNo, detailInfo, stockInfo, loginId, isSplit, cartonNo, SplitQty, rackOrCartNo);

                }
                else
                {
                    //获取扫描的箱条码
                    SysStock_Extend stockInfo2 = repository.GetCartonNoInfo2(cartonNo);
                    if (stockInfo2 == null)
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "扫描的箱条码不存在，请检查！";
                        return rfInfo;
                    }
                    else
                    {
                        if (detailInfo.Count != 0)
                        {
                            List<WmsMoveDetail_Extend> IsExist = detailInfo.Where(x => x.PartNo == stockInfo2.PartNo).ToList();
                            if (IsExist.Count == 0)
                            {
                                rfInfo.type = "FAIL";
                                rfInfo.message = "箱条码的物料与单据物料不匹配，请检查！";
                                return rfInfo;
                            }
                            else
                            {
                                decimal pickQty = IsExist.FirstOrDefault().PickQty;
                                decimal Qty = IsExist.FirstOrDefault().Qty;
                                decimal residueQtyf = Qty - pickQty;

                                if (Qty < pickQty)
                                {
                                    rfInfo.type = "FAIL";
                                    rfInfo.message = "单据内配料数量已超出物料数量，请检查！";
                                    return rfInfo;
                                }
                                if (stockInfo2.Qty > residueQtyf)
                                {
                                    rfInfo.type = "FAIL";
                                    rfInfo.message = "扫描数量大于剩余配料数量，请检查！";
                                    return rfInfo;
                                }
                            }

                            //判断扫描的箱条码是否有绑定关系，有的话解绑
                            WmsRackPackage_Extend packInfo = repository.GetpackageInfo(cartonNo);
                            if (packInfo != null)
                            {
                                string aa = repository.UpdatepackageInfo(cartonNo);
                            }


                            //判断是否存在在途库位
                            SysLocate locateInfo = repository.GetLocateZTbin();
                            if (locateInfo == null)
                            {
                                rfInfo.type = "FAIL";
                                rfInfo.message = "条码对应的库存地下没有在途库位，请检查！";
                                return rfInfo;
                            }
                            int i = Convert.ToInt32(stockInfo2.Qty);
                            SplitQty = i.ToString();
                            return repository.UpdteStatusBatach(locateInfo.LocateId, locateInfo.LocateName, orderNo, IsExist, stockInfo2, loginId, isSplit, cartonNo, SplitQty, rackOrCartNo);
                        }
                        else
                        {
                            rfInfo.type = "FAIL";
                            rfInfo.message = "该单据中没有对应的条码信息，请检查!";
                            return rfInfo;
                        }
                    }

                }

            }


            return rfInfo;
        }


        /// <summary>
        /// 获取列表信息
        /// </summary>
        /// <param name="loginId"></param>
        /// <param name="rackNo"></param>
        /// <param name="isSplit"></param>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public SetObjectDetail GetRackPackageList(string cartNo, string isSplit)
        {
            SetObjectDetail rfInfo = new SetObjectDetail();
            if (isSplit == "True")
            {
                //获取周转箱中是否有物料（有物料不一致进行报错）
                List<WmsRackPackage_Extend> rackPackageInfo = repository.GetCartonInfo(cartNo);
                if (rackPackageInfo.Count != 0)
                {
                    rfInfo.type = "PASS";
                    //rfInfo.message = "操作成功!请扫描周转箱或箱条码";
                    rfInfo.wmsObjectDetail = rackPackageInfo.ConvertAll(s => (object)s);
                }
            }
            return rfInfo;
        }


        /// <summary>
        ///拆箱- 扫描周转箱
        /// </summary>
        /// <param name="loginId"></param>
        /// <param name="rackNo"></param>
        /// <param name="isSplit"></param>
        /// <returns></returns>
        public SetObjectDetail CheckRackNo(string loginId, string rackNo, string isSplit, string orderNo)
        {
            SetObjectDetail rfInfo = new SetObjectDetail();
            if (isSplit == "True")
            {
                //判断扫码的是箱条码还是周转箱
                SysStock stockInfo = repository.GetStockCartonInfo(rackNo);
                if (stockInfo != null && stockInfo.CartonType == 1)
                {
                    //获取单据的物料信息
                    List<WmsMoveDetail_Extend> detailInfo = repository.GetMoveDetailInfo(orderNo);
                    //获取周转箱中是否有物料（有物料不一致进行报错）
                    List<WmsRackPackage_Extend> rackPackageInfo = repository.GetCartonInfo(rackNo);
                    if (rackPackageInfo.Count != 0)
                    {
                        for (int i = 0; i < rackPackageInfo.Count; i++)
                        {
                            List<WmsMoveDetail_Extend> packagelist = detailInfo.Where(x => x.PartNo == rackPackageInfo[i].PartNo).ToList();
                            if (packagelist.Count == 0)
                            {
                                rfInfo.type = "FAIL";
                                rfInfo.message = "扫描的周转箱存在其他物料信息，请检查！";
                                return rfInfo;
                            }
                        }
                        rfInfo.type = "PASS";
                        rfInfo.message = "操作成功!请扫描箱条码或周转箱！";
                        rfInfo.wmsObjectDetail = rackPackageInfo.ConvertAll(s => (object)s);
                    }
                    else
                    {
                        rfInfo.type = "PASS";
                        rfInfo.message = "操作成功!请扫描箱条码或周转箱！";
                        return rfInfo;
                    }
                }
                else
                {
                    rfInfo.type = "FAIL";
                    rfInfo.message = "请扫描周转箱！";
                    return rfInfo;
                }
            }
            else
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "请打开拆箱按钮后，再扫描周转箱！";
                return rfInfo;
            }
            return rfInfo;
        }


        /// <summary>
        /// 拆箱-扫描箱条码或周转箱
        /// </summary>
        /// <param name="loginId"></param>
        /// <param name="rackNo"></param>
        /// <param name="isSplit"></param>
        /// <param name="cartNo"></param>
        /// <returns></returns>
        public SetObjectDetail CheckCartNo(string loginId, string isSplit, string cartNo, string orderNo, string rackNo)
        {
            SetObjectDetail rfInfo = new SetObjectDetail();
            //if (isSplit == "True")
            //{
            //获取单据的物料信息
            List<WmsMoveDetail_Extend> detailInfo = repository.GetMoveDetailInfo(orderNo);

            //判断扫码的是箱条码还是周转箱
            SysStock stockInfo = repository.GetStockCartonInfo(cartNo);
            if (stockInfo != null && stockInfo.CartonType == 1)
            {
                //获取周转箱中的物料
                List<WmsRackPackage_Extend> rackPackageInfo = repository.GetCartonInfo(cartNo);

                //验证周转箱的物料是否包含单据内的物料
                for (int i = 0; i < detailInfo.Count; i++)
                {
                    List<WmsRackPackage_Extend> snlist = rackPackageInfo.Where(x => x.PartNo == detailInfo[i].PartNo).ToList();
                    if (snlist.Count == 0)
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "周转箱内物料与单据物料不一致！";
                        return rfInfo;
                    }
                }
                //包含：在界面下面显示物料的信息，单击物料信息，将数量反填到文本
                if (rackPackageInfo.Count > 0)
                {
                    rfInfo.type = "PASS";
                    rfInfo.message = "操作成功!请选择物料输入拆分数量";
                    rfInfo.wmsObjectDetail = rackPackageInfo.ConvertAll(s => (object)s);
                }
                else
                {
                    rfInfo.type = "FAIL";
                    rfInfo.message = "未查询到数据，请检查！";
                }
                //输入数量，验证当前的物料条码在单据内是否存在，不存在报错
                //存在，验证进行拆分
            }
            else
            {
                List<WmsRackPackage_Extend> rackPackageInfo = repository.GetCartonInfo(rackNo);
                List<WmsRackPackage_Extend> wmsRacks = rackPackageInfo.Where(x => x.CortonNo == cartNo).ToList();
                if (wmsRacks.Count != 0)
                {
                    rfInfo.type = "FAIL";
                    rfInfo.message = "不能扫描目的周转箱中的物料条码！";
                    return rfInfo;
                }
                //获取扫描的箱条码
                SysStock_Extend stockInfo2 = repository.GetCartonNoInfo2(cartNo);
                if (stockInfo2 == null)
                {
                    rfInfo.type = "FAIL";
                    rfInfo.message = "扫描的箱条码不存在，请检查！";
                    return rfInfo;
                }
                else
                {
                    //获取单据的物料信息
                    //List<WmsMoveDetail_Extend> detailInfo = repository.GetMoveDetailInfo(orderNo);
                    if (detailInfo.Count != 0)
                    {
                        var IsExist = detailInfo.Where(x => x.PartNo == stockInfo2.PartNo).ToList();
                        if (IsExist.Count == 0)
                        {
                            rfInfo.type = "FAIL";
                            rfInfo.message = "箱条码的物料与单据物料不匹配，请检查!";
                            return rfInfo;
                        }
                        rfInfo.type = "PASS";
                        rfInfo.message = "操作成功，请输入拆分数量！";
                        rfInfo.wmsObjectDetail = null;
                        return rfInfo;
                    }
                    else
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "该单据中没有对应的物料信息，请检查!";
                        return rfInfo;
                    }
                }
            }
            //}
            //else
            //{
            //    rfInfo.type = "FAIL";
            //    rfInfo.message = "请打开拆箱按钮后，再扫描箱条码！";
            //    return rfInfo;
            //}
            return rfInfo;
        }

        /// <summary>
        /// 翻箱-拆分
        /// </summary>
        /// <param name="loginId"></param>
        /// <param name="isSplit"></param>
        /// <param name="cartNo"></param>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public SetObjectDetail ScanSplitQty(string loginId, string rackNo, string rackOrCartNo, string SplitQty, string cartonNo)
        {
            SetObjectDetail rfInfo = new SetObjectDetail();//返回消息
            if (string.IsNullOrEmpty(cartonNo))
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "请选择列表中的箱条码!";
                return rfInfo;
            }

            int intSplitQty = Convert.ToInt32(SplitQty);
            //获取扫描的箱条码
            SysStock_Extend stockInfo = repository.GetCartonNoInfo2(cartonNo);
            if (stockInfo == null)
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "扫描的条码不存在，请检查！";
                return rfInfo;
            }

            WmsRackPackage_Extend rackPackageInfo = repository.GetpackageInfo(cartonNo);
            if (rackPackageInfo != null)
            {
                int intRackNum = Convert.ToInt32(rackPackageInfo.RackNum);
                if (intRackNum < intSplitQty)
                {
                    rfInfo.type = "FAIL";
                    rfInfo.message = "数量不能大于箱条码中的数量，请检查！";
                    return rfInfo;
                }
            }


            //根据周转箱号去条码表找对应的信息
            SysStock cartonInfo = repository.CheckCartonNoStatus(rackNo);

            if (stockInfo.Qty == intSplitQty)
            {
                //需要拆分的箱条码信息
                List<SysStock> MaterialInfo = repository.GetMaterialInfo(cartonNo);
                //数量一致不进行拆分，直接更新stock表库位、状态配料中
                //更新周转箱中的条码为目的周转箱
                repository.UpdatePickingLocate(rackPackageInfo, cartonInfo.LocateId, cartonInfo.LocateName, rackNo, MaterialInfo, intSplitQty, loginId);
            }
            else
            {
                PickingCheckMaterialSplit(cartonInfo.LocateId, cartonInfo.LocateName, rackNo, cartonNo, intSplitQty, loginId, 1);
            }

            //更新拆分后数据
            stockInfo = repository.GetCartonNoInfo2(cartonNo);
            repository.UpdtePickingInfo(rackPackageInfo, stockInfo, loginId, rackNo, SplitQty, rackOrCartNo, cartonInfo.LocateId, cartonInfo.LocateName);

            //List<WmsRackPackage_Extend> PackageInfo = repository.GetCartonInfo(rackNo);

            List<WmsRackPackage_Extend> PackageInfo = repository.GetRackPackageInfo(rackNo);
            if (PackageInfo.Count > 0)
            {
                rfInfo.type = "PASS";
                rfInfo.message = "[" + cartonNo + "]:单据操作完成!";
                rfInfo.wmsObjectDetail = PackageInfo.ConvertAll(s => (object)s);
            }
            else
            {
                rfInfo.type = "PASS";
                rfInfo.message = "[" + cartonNo + "]:单据操作完成!";
            }
            return rfInfo;
        }



        /// <summary>
        /// 配料-拆分
        /// </summary>
        /// <param name="loginId"></param>
        /// <param name="isSplit"></param>
        /// <param name="cartNo"></param>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public SetObjectDetail CheckSplitQty(string loginId, string isSplit, string cartNo, string orderNo, string rackNo, string SplitQty, string rackOrCartNo)
        {
            SetObjectDetail rfInfo = new SetObjectDetail();//返回消息
            int intSplitQty = Convert.ToInt32(SplitQty);

            if (string.IsNullOrEmpty(cartNo))
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "请选择列表中的箱条码!";
                return rfInfo;
            }
            //获取扫描的箱条码
            SysStock_Extend stockInfo = repository.GetCartonNoInfo2(cartNo);
            if (stockInfo.Qty < intSplitQty)
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "输入的拆分数量不能大于条码中的物料数量，请检查!";
                return rfInfo;
            }
            //获取单据的物料信息
            List<WmsMoveDetail_Extend> detailInfo = repository.GetMoveDetailInfo(orderNo);
            //判断输入的数量是否打印单据内物料的数量
            List<WmsMoveDetail_Extend> detInfo = detailInfo.Where(x => x.PartNo == stockInfo.PartNo).ToList();
            if (detInfo.Count != 0)
            {
                string partNo = detInfo.FirstOrDefault().PartNo;
                decimal pickQty = detInfo.FirstOrDefault().PickQty;
                decimal Qty = detInfo.FirstOrDefault().Qty;
                decimal residueQtyf = Qty - pickQty;
                decimal detSplitQty = Convert.ToDecimal(SplitQty);

                if (pickQty > Qty)
                {
                    rfInfo.type = "FAIL";
                    rfInfo.message = "单据内配料数量已超出物料数量，请检查！";
                    return rfInfo;
                }
                if (intSplitQty > residueQtyf)
                {
                    rfInfo.type = "FAIL";
                    rfInfo.message = "扫描数量大于剩余配料数量，请检查！";
                    return rfInfo;
                }
                if (detInfo.FirstOrDefault().Qty >= intSplitQty)
                {
                    //判断是否存在在途库位
                    SysLocate locateInfo = repository.GetLocateZTbin();
                    if (locateInfo == null)
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "条码对应的库存地下没有在途库位，请检查！";
                        return rfInfo;
                    }
                    //获取周转箱中的物料
                    List<WmsRackPackage_Extend> rackPackageInfo = repository.GetCartonInfo(orderNo);
                    List<WmsRackPackage_Extend> packlist = rackPackageInfo.Where(x => x.PartNo == partNo).ToList();

                    //原条码
                    //decimal oldQty = stockInfo.Qty - intSplitQty;
                    decimal oldQty = intSplitQty;
                    CheckMaterialSplit(locateInfo.LocateId, locateInfo.LocateName, rackNo, packlist, detInfo, stockInfo.CartonNo, Convert.ToInt32(oldQty), loginId, 1);
                    //更新拆分后数据

                    stockInfo = repository.GetCartonNoInfo2(cartNo);
                    repository.UpdteStatus(locateInfo.LocateId, locateInfo.LocateName, orderNo, detInfo, stockInfo, loginId, isSplit, rackNo, SplitQty, rackOrCartNo);

                    List<WmsRackPackage_Extend> PackageInfo = repository.GetCartonInfo(rackNo);
                    if (PackageInfo.Count > 0)
                    {
                        rfInfo.type = "PASS";
                        rfInfo.message = "[" + cartNo + "]:单据操作完成!";
                        rfInfo.wmsObjectDetail = PackageInfo.ConvertAll(s => (object)s);
                    }
                    else
                    {
                        rfInfo.type = "[" + cartNo + "]:单据操作完成!";
                        rfInfo.message = "单据操作完成!";
                    }
                    return rfInfo;
                }
                else
                {
                    rfInfo.type = "FAIL";
                    rfInfo.message = "输入的拆分数量不能大于单据中的物料数量，请检查!";
                    return rfInfo;
                }
            }
            else
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "该物料条码不包含在单据内，请检查!";
                return rfInfo;
            }
        }


        public SetObjectDetail PickingCheckMaterialSplit(int? locateId, string locateCode, string rackNo, string cartonNo, int splitNum, string loginId, int splitCount)
        {

            SetObjectDetail det = new SetObjectDetail();
            //需要拆分的箱条码信息
            List<SysStock> MaterialInfo = repository.GetMaterialInfo(cartonNo);
            if (MaterialInfo.Count == 0)
            {
                det.type = "NO";
                det.message = "[" + cartonNo + "]:箱条码不存在，请检查!";
                return det;
            }
            if (MaterialInfo[0].Enabled.Equals("N"))
            {
                det.type = "NO";
                det.message = "[" + cartonNo + "]:箱条码已被冻结，请检查!";
                return det;
            }
            //if (MaterialInfo[0].Status != (int)WmsEnumUtil.StockStatus.INSTOCKED)
            //{
            //    det.type = "NO";
            //    det.message = "[" + cartonNo + "]:箱条码不处于在库状态!";
            //    return det;
            //}
            if (MaterialInfo[0].Qty < 1)
            {
                det.type = "NO";
                det.message = "[" + cartonNo + "]:箱条码数量不足，无法拆分!";
                return det;
            }


            List<SysStock> NewStock = repository.PickingCheckMaterialSplit(locateId, locateCode, rackNo, MaterialInfo, splitNum, loginId, splitCount);
            if (NewStock == null || NewStock.Count == 0)
            {
                det.type = "NO";
                det.message = "执行失败！请重试！";
            }
            else
            {
                det.type = "OK";
                det.wmsObjectDetail = NewStock.ConvertAll(s => (object)s);
            }
            return det;
        }


        public SetObjectDetail CheckMaterialSplit(int locateId, string locateCode, string rackNo, List<WmsRackPackage_Extend> packlist, List<WmsMoveDetail_Extend> detInfo, string cartonNo, int splitNum, string loginId, int splitCount)
        {

            SetObjectDetail det = new SetObjectDetail();
            //需要拆分的箱条码信息
            List<SysStock> MaterialInfo = repository.GetMaterialInfo(cartonNo);
            if (MaterialInfo.Count == 0)
            {
                det.type = "NO";
                det.message = "[" + cartonNo + "]:箱条码不存在，请检查!";
                return det;
            }
            if (MaterialInfo[0].Enabled.Equals("N"))
            {
                det.type = "NO";
                det.message = "[" + cartonNo + "]:箱条码已被冻结，请检查!";
                return det;
            }
            //if (MaterialInfo[0].Status != (int)WmsEnumUtil.StockStatus.INSTOCKED)
            //{
            //    det.type = "NO";
            //    det.message = "[" + cartonNo + "]:箱条码不处于在库状态!";
            //    return det;
            //}
            if (MaterialInfo[0].Qty < 1)
            {
                det.type = "NO";
                det.message = "[" + cartonNo + "]:箱条码数量不足，无法拆分!";
                return det;
            }


            List<SysStock> NewStock = repository.CheckMaterialSplit(locateId, locateCode, rackNo, packlist, detInfo, MaterialInfo, splitNum, loginId, splitCount);
            if (NewStock == null || NewStock.Count == 0)
            {
                det.type = "NO";
                det.message = "执行失败！请重试！";
            }
            else
            {
                det.type = "OK";
                det.wmsObjectDetail = NewStock.ConvertAll(s => (object)s);
            }
            return det;
        }


        public SetObjectDetail GetMoveSourceOrderList(string orderNo)
        {
            SetObjectDetail rfInfo = new SetObjectDetail();//返回消息
            List<WmsMoveHeader> wmsMoves = repository.GetMoveSourceOrderList(orderNo);

            if (wmsMoves.Count > 0)
            {
                rfInfo.type = "PASS";
                rfInfo.message = "成功";
                rfInfo.wmsObjectDetail = wmsMoves.ConvertAll(s => (object)s);
            }
            else
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "未查询到数据，请检查！";
            }
            return rfInfo;
        }

        public SetObjectDetail GetMoveSourceListByOrderNo(string orderNo)
        {
            SetObjectDetail rfInfo = new SetObjectDetail();
            List<WmsMoveHeader> wmsMoves = repository.GetMoveSourceListByOrderNo(orderNo);
            if (wmsMoves.Count > 0)
            {
                for (int i = 0; i < wmsMoves.Count; i++)
                {
                    int intPickQty = Convert.ToInt32(wmsMoves[i].PickQty);
                    int intQty = Convert.ToInt32(wmsMoves[i].Qty);
                    if (intPickQty > intQty)
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "已配料数量超出物料数量范围，请检查！";
                        rfInfo.wmsObjectDetail = wmsMoves.ConvertAll(s => (object)s);
                        return rfInfo;
                    }
                    if (intPickQty < intQty)
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "该单据物料未完成配料不允许操作！";
                        rfInfo.wmsObjectDetail = wmsMoves.ConvertAll(s => (object)s);
                        return rfInfo;
                    }
                }
                rfInfo.type = "PASS";
                rfInfo.message = "成功";
                rfInfo.wmsObjectDetail = wmsMoves.ConvertAll(s => (object)s);
            }
            else
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "未查询到数据，请检查！";
            }
            return rfInfo;
        }


        /// <summary>
        /// 配料-提交完成的单据至ERP
        /// </summary>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public string SubmitMoveOrderGoERP(string orderNo)
        {
            List<WmsMoveDetail> moveDetails = repository.GetMoveDetailList(orderNo);

            var moveDetailsExist = moveDetails.Where(a => a.Qty == a.PickQty).ToList();
            if (moveDetailsExist != null)
            {
                repository.InsertInterfaceByNCConcession(moveDetails);//添加到接口表
                return "OK";
            }
            return "OK";
        }



        /// <summary>
        /// 接收-扫描周转箱或箱条码
        /// </summary>
        /// <param name="loginId"></param>
        /// <param name="cartonNo"></param>
        /// <param name="locateName"></param>
        /// <returns></returns>
        public string CheckRackMoveOrder(string cartonNo, string orderNo, string locateName, string loginId)
        {
            //获取单据中条码的物料信息
            List<WmsMoveSn> moveSnInfo = repository.GetMoveSnInfo(orderNo);

            List<SysLocate> sysLocate = repository.CheckLocateStatus(locateName);
            int intLocateId = sysLocate.Count == 0 ? 0 : sysLocate.FirstOrDefault().LocateId;
            string strLocateName = sysLocate.Count == 0 ? null : sysLocate.FirstOrDefault().LocateName;
            List<WmsMoveDetail> wmsMoveDetails = repository.CheckMoveOrderLocate(orderNo);

            //判断扫描的是周转箱还是箱条码
            SysStock stockInfo = repository.GetStockCartonInfo(cartonNo);
            if (stockInfo != null && stockInfo.CartonType == 1)
            {
                //获取周转箱中的物料
                List<WmsRackPackage_Extend> rackPackageInfo = repository.GetCartonInfo(cartonNo);

                //判断周转箱内物料是否和单据物料一致
                for (int i = 0; i < rackPackageInfo.Count; i++)
                {
                    List<WmsMoveSn> snlist = moveSnInfo.Where(x => x.PartNo == rackPackageInfo[i].PartNo).ToList();
                    if (snlist.Count == 0)
                    {
                        return "NO周转箱内物料与单据物料不一致！";
                    }
                }


                return repository.UpdteMoveStatus(wmsMoveDetails, orderNo, moveSnInfo, stockInfo, loginId, intLocateId, strLocateName);
            }
            else
            {
                //获取扫描的箱条码
                SysStock_Extend stockInfo2 = repository.GetCartonNoInfo2(cartonNo);
                if (stockInfo2 == null)
                {
                    return "NO扫描的箱条码不存在，请检查！";
                }
                else
                {
                    if (moveSnInfo.Count != 0)
                    {
                        List<WmsMoveSn> IsExist = moveSnInfo.Where(x => x.PartNo == stockInfo2.PartNo && x.CartonNo == stockInfo2.CartonNo).ToList();
                        if (IsExist.Count == 0)
                        {
                            return "NO箱条码或物料与单据不匹配，请检查！";
                        }

                        return repository.UpdteMoveStatus(wmsMoveDetails, orderNo, IsExist, stockInfo2, loginId, intLocateId, strLocateName);
                    }
                    else
                    {
                        return "NO该单据中没有对应的条码信息，请检查!";
                    }
                }

            }

        }

        /// <summary>
        /// 组托-刷新
        /// </summary>
        /// <param name="loginId"></param>
        /// <param name="rackNo"></param>
        /// <returns></returns>
        public SetObjectDetail GetShowList(string loginId, string rackNo)
        {
            SetObjectDetail rfInfo = new SetObjectDetail();

            List<WmsRackPackage_Extend> rackPackageInfo = repository.GetRackCartonList(rackNo);

            rfInfo.type = "PASS";
            rfInfo.message = "操作成功!";
            rfInfo.wmsObjectDetail = rackPackageInfo.ConvertAll(s => (object)s);
            return rfInfo;
        }


        /// <summary>
        /// 组托-扫描托条码
        /// </summary>
        /// <param name="loginId"></param>
        /// <param name="rackNo"></param>
        /// <param name="isHandover"></param>
        /// <returns></returns>
        public SetObjectDetail CheckTorr(string loginId, string rackNo)
        {
            SetObjectDetail rfInfo = new SetObjectDetail();

            WmsRack_Extend rackInfo = repository.GetRackInfo2(rackNo);
            SysStock_Extend stockInfo = repository.GetCartonNoInfo2(rackNo);
            if (stockInfo == null)
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "[" + rackNo + "]:扫描的条码不存在，请检查!";
                return rfInfo;
            }
            if (rackInfo == null)
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "[" + rackNo + "]:未维护托条码信息，请检查!";
                return rfInfo;
            }
            if (rackInfo.PackageType != 2)
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "请扫描托条码!";
                return rfInfo;
            }
            List<WmsRackPackage_Extend> rackPackageInfo = repository.GetRackCartonList(rackNo);


            rfInfo.type = "PASS";
            rfInfo.message = "操作成功!请扫描托/周转箱/物料箱条码";
            rfInfo.wmsObjectDetail = rackPackageInfo.ConvertAll(s => (object)s);
            return rfInfo;
        }


        /// <summary>
        /// 组托-扫描条码（托/周转箱/物料箱条码）
        /// </summary>
        /// <param name="loginId"></param>
        /// <param name="cartonNo">条码</param>
        /// <param name="isGroup">是否拆分</param>
        /// <param name="rackNo">托</param>
        /// <returns></returns>
        public SetObjectDetail CheckLotGroupBarcode(string rackNo, string cartonNo, string isGroup, string loginId)
        {
            SetObjectDetail rfInfo = new SetObjectDetail();
            if (cartonNo == rackNo)
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "[" + cartonNo + "]:不能扫描同级别托条码，请检查!";
                return rfInfo;
            }

            //SysStock stockInfo = repository.GetStockCartonInfo(cartonNo);

            SysStock_Extend stockInfo = repository.GetCartonNoInfo2(cartonNo);
            if (stockInfo == null)
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "[" + cartonNo + "]:扫描的条码不存在，请检查!";
                return rfInfo;
            }
            if (isGroup == "True")  //拆分
            {
                if (stockInfo.CartonType == 2)
                {

                    //获取托下面的所有物料条码
                    List<WmsRackPackage_Extend> rackPackageInfo = repository.GetRackCartonList(cartonNo);


                    if (rackPackageInfo.Count > 0)
                    {
                        rfInfo.type = "PASS";
                        rfInfo.message = "操作成功!请选择需要拆分的物料条码";
                        rfInfo.wmsObjectDetail = rackPackageInfo.ConvertAll(s => (object)s);
                    }
                    else
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "未查询到数据，请检查！";
                        return rfInfo;
                    }
                }
                else if (stockInfo.CartonType == 1)
                {
                    List<WmsRackPackage_Extend> rackPackageInfo = repository.GetCartonInfo(cartonNo);

                    if (rackPackageInfo.Count > 0)
                    {
                        rfInfo.type = "PASS";
                        rfInfo.message = "操作成功!请选择物料输入拆分数量";
                        rfInfo.wmsObjectDetail = rackPackageInfo.ConvertAll(s => (object)s);
                    }
                    else
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "未查询到数据，请检查！";
                        return rfInfo;
                    }
                }
                else
                {
                    if (stockInfo == null)
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "[" + cartonNo + "]:条码不可用，请检查!";
                        return rfInfo;
                    }
                    if (stockInfo.Enabled.Equals("N"))
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "[" + cartonNo + "]:箱条码已冻结，无法操作!";
                        return rfInfo;
                    }
                    if (stockInfo.Status != (int)StockStatus.INSTOCKED)
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "[" + cartonNo + "]:该条码为" + stockInfo.StockStatus + "状态，请检查!";
                        return rfInfo;
                    }
                    rfInfo.type = "PASS";
                    rfInfo.message = "请输入需要拆分的数量！";
                    rfInfo.wmsObjectDetail = null;
                    return rfInfo;
                }
            }
            else  //不拆分
            {

                if (stockInfo.CartonType == 2)
                {
                    //查询托下面的周转箱
                    List<WmsRackPackage_Extend> getrackList = repository.GetTorrRackList(cartonNo);

                    if (getrackList.Count > 0)
                    {
                        rfInfo.type = "PASS";
                        rfInfo.message = "操作成功!请选择需要拆分的周转箱";
                        rfInfo.wmsObjectDetail = getrackList.ConvertAll(s => (object)s);
                    }
                    else
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "未查询到数据，请检查！";
                        return rfInfo;
                    }
                }
                else if (stockInfo.CartonType == 1)
                {
                    List<WmsRackPackage_Extend> rackPackageInfo = repository.GetCartonInfo(cartonNo);
                    SysStock_Extend stockInfo2 = null;
                    if (rackPackageInfo.Count != 0)
                    {
                        repository.CheckFullBoxPicking(rackPackageInfo, stockInfo2, rackNo, cartonNo, loginId);
                    }
                    rfInfo.type = "PASS";
                    rfInfo.message = "[" + cartonNo + "]:操作完成!";
                    return rfInfo;
                }
                else
                {
                    //判断箱条码是否可用
                    //SysStock_Extend cartonInfo = repository.CheckCartonNoStatus(cartonNo);
                    if (stockInfo == null)
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "[" + cartonNo + "]:条码不可用，请检查!";
                        return rfInfo;
                    }
                    if (stockInfo.Enabled.Equals("N"))
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "[" + cartonNo + "]:箱条码已冻结，无法操作!";
                        return rfInfo;
                    }
                    if (stockInfo.Status != (int)StockStatus.INSTOCKED && stockInfo.Status != (int)StockStatus.WAITING_INSTOCK)
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "[" + cartonNo + "]:该条码为" + stockInfo.StockStatus + "状态，请检查!";
                        return rfInfo;
                    }

                    List<WmsRackPackage_Extend> rackPackageInfo = repository.GetRackCartonInfo(cartonNo);

                    //将条码绑定到托条码上
                    repository.CheckFullBoxPicking(rackPackageInfo, stockInfo, rackNo, cartonNo, loginId);
                    rfInfo.type = "PASS";
                    rfInfo.message = "[" + cartonNo + "]:操作完成!";
                    return rfInfo;
                }
            }
            return rfInfo;
        }



        /// <summary>
        /// 组托-拆分
        /// </summary>
        /// <param name="rackNo">托</param>
        /// <param name="cartonNo">箱条码</param>
        /// <param name="rackOrcartNo"></param>
        /// <param name="isGroup"></param>
        /// <param name="SplitQty"></param>
        /// <param name="loginId"></param>
        /// <returns></returns>
        public SetObjectDetail CheckLotGroupSplitQty(string rackNo, string cartonNo, string rackOrcartNo, string isGroup, string SplitQty, string loginId)
        {
            SetObjectDetail rfInfo = new SetObjectDetail();//返回消息

            int intSplitQty = Convert.ToInt32(SplitQty);
            SysStock_Extend torrInfo = repository.GetCartonNoInfo2(rackNo);
            //获取扫描的箱条码
            SysStock_Extend stockInfo = repository.GetCartonNoInfo2(cartonNo);

            //List<SysStock> MaterialInfo = repository.GetMaterialInfo(cartonNo);

            if (string.IsNullOrEmpty(cartonNo))
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "请选择列表中的箱条码!";
                return rfInfo;
            }
            if (stockInfo == null)
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "扫描的条码不存在，请检查！";
                return rfInfo;
            }
            WmsRackPackage_Extend rackPackageInfo = repository.GetpackageInfo(cartonNo);
            if (rackPackageInfo != null)
            {
                int intRackNum = Convert.ToInt32(rackPackageInfo.RackNum);
                if (intRackNum < intSplitQty)
                {
                    rfInfo.type = "FAIL";
                    rfInfo.message = "数量不能大于箱条码中的数量，请检查！";
                    return rfInfo;
                }
            }
            //验证库区是否存在
            if (torrInfo.ZoneId != 0 && !string.IsNullOrEmpty(torrInfo.ZoneName))
            {
                if (stockInfo.ZoneId != 0)
                {
                    if (torrInfo.ZoneId != stockInfo.ZoneId || torrInfo.ZoneName != stockInfo.ZoneName)
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "扫描条码的库区与托条码库区不一致，请检查！";
                        return rfInfo;
                    }
                }
            }
            if (stockInfo.ZoneId != 0 && !string.IsNullOrEmpty(stockInfo.ZoneName))
            {
                if (torrInfo.ZoneId == 0 && string.IsNullOrEmpty(torrInfo.ZoneName))
                {
                    //记录到扫描的托条码stock的库区中，清空扫描条码的库位
                    repository.UpdateStockInfo(rackNo, cartonNo, stockInfo.ZoneId, stockInfo.ZoneName, loginId);
                }
            }

            //获取周转箱信息
            if (stockInfo.Qty == intSplitQty)
            {
                //需要拆分的箱条码信息
                List<SysStock> MaterialInfo = repository.GetMaterialInfo(cartonNo);
                repository.UpdatePickingLocate(rackPackageInfo, torrInfo.LocateId, torrInfo.LocateName, rackNo, MaterialInfo, intSplitQty, loginId);
            }
            else
            {
                //拆分出的条码与那个一致？
                PickingCheckMaterialSplit(torrInfo.LocateId, torrInfo.LocateName, rackNo, cartonNo, intSplitQty, loginId, 1);
            }

            //更新拆分后数据
            stockInfo = repository.GetCartonNoInfo2(cartonNo);
            repository.UpdtePickingInfo(rackPackageInfo, stockInfo, loginId, rackNo, SplitQty, rackOrcartNo, torrInfo.LocateId, torrInfo.LocateName);

            //List<WmsRackPackage_Extend> PackageInfo = repository.GetCartonInfo(rackNo);

            List<WmsRackPackage_Extend> PackageInfo = repository.GetRackPackageInfo(rackNo);
            if (PackageInfo.Count > 0)
            {
                rfInfo.type = "PASS";
                rfInfo.message = "[" + cartonNo + "]:单据操作完成!";
                rfInfo.wmsObjectDetail = PackageInfo.ConvertAll(s => (object)s);
            }
            else
            {
                rfInfo.type = "PASS";
                rfInfo.message = "[" + cartonNo + "]:单据操作完成!";
            }
            return rfInfo;
        }



        /// <summary>
        /// 退料-显示退料单
        /// </summary>
        /// <param name="onLine"></param>
        /// <returns></returns>
        public List<WmsMoveHeader> GetReturnMaterialInfo(string onLine)
        {

            return repository.GetReturnMaterialInfo(onLine);
        }



        /// <summary>
        /// 退料-扫描条码（周转箱/物料箱条码）
        /// </summary>
        /// <param name="rackOrcartNo"></param>
        /// <param name="loginId"></param>
        /// <returns></returns>
        public SetObjectDetail CheckReturnMaterialBarcode(string rackOrcartNo, string loginId)
        {
            SetObjectDetail rfInfo = new SetObjectDetail();

            SysStock_Extend stockInfo = repository.GetCartonNoInfo2(rackOrcartNo);
            SysStock_Extend getzoneType = repository.GetCartonNoZoneType(rackOrcartNo);
            if (stockInfo == null)
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "[" + rackOrcartNo + "]:扫描的条码不存在，请检查!";
                return rfInfo;
            }
            if (getzoneType == null)
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "[" + rackOrcartNo + "]:请扫描线边库区的条码!";
                return rfInfo;
            }

            if (stockInfo.CartonType == 1)
            {
                List<WmsRackPackage_Extend> rackPackageInfo = repository.GetrackPackageInfo(rackOrcartNo);

                if (rackPackageInfo.Count > 0)
                {
                    rfInfo.type = "PASS";
                    rfInfo.message = "操作成功!请选择物料输入拆分数量";
                    rfInfo.wmsObjectDetail = rackPackageInfo.ConvertAll(s => (object)s);
                }
                else
                {
                    rfInfo.type = "FAIL";
                    rfInfo.message = "未查询到数据，请检查！";
                    return rfInfo;
                }
            }
            else if (stockInfo.CartonType == 0)
            {
                if (stockInfo == null)
                {
                    rfInfo.type = "FAIL";
                    rfInfo.message = "[" + rackOrcartNo + "]:条码不可用，请检查!";
                    return rfInfo;
                }
                if (stockInfo.Enabled.Equals("N"))
                {
                    rfInfo.type = "FAIL";
                    rfInfo.message = "[" + rackOrcartNo + "]:箱条码已冻结，无法操作!";
                    return rfInfo;
                }
                if (stockInfo.Status != (int)StockStatus.INSTOCKED)
                {
                    rfInfo.type = "FAIL";
                    rfInfo.message = "[" + rackOrcartNo + "]:该条码为" + stockInfo.StockStatus + "状态，请检查!";
                    return rfInfo;
                }
                List<WmsRackPackage_Extend> cartnoPackageInfo = repository.GetcartnoPackageInfo(rackOrcartNo);
                rfInfo.type = "PASS";
                rfInfo.message = "请输入需要拆分的数量！";
                rfInfo.wmsObjectDetail = cartnoPackageInfo.ConvertAll(s => (object)s);
                return rfInfo;
            }
            else
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "请扫描周转箱或箱条码!";
                return rfInfo;
            }
            return rfInfo;
        }



        /// <summary>
        /// 退料-拆分
        /// </summary>
        /// <param name="rackOrcartNo"></param>
        /// <param name="cartonNo"></param>
        /// <param name="SplitQty"></param>
        /// <param name="loginId"></param>
        /// <returns></returns>
        public SetObjectDetail CheckReturnMaterialSplitQty(string orderNo, string rackOrcartNo, string cartonNo, string SplitQty, string loginId)
        {
            SetObjectDetail rfInfo = new SetObjectDetail();//返回消息

            int intSplitQty = Convert.ToInt32(SplitQty);
            //获取扫描的箱条码
            SysStock_Extend stockInfo = repository.GetCartonNoInfo2(cartonNo);

            if (string.IsNullOrEmpty(cartonNo))
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "请选择列表中的箱条码!";
                return rfInfo;
            }
            if (stockInfo == null)
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "扫描的条码不存在，请检查！";
                return rfInfo;
            }
            WmsRackPackage_Extend rackPackageInfo = repository.GetpackageInfo(cartonNo);

            List<WmsMoveDetail> wmsMoveDetails = repository.CheckMoveOrderLocate(orderNo);
            List<WmsMoveDetail> details = wmsMoveDetails.Where(x => x.PartNo == stockInfo.PartNo && x.PartId == stockInfo.PartId).ToList();
            if (details.Count == 0)
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "扫描的物料与单据物料不一致，请检查！";
                return rfInfo;
            }
            else
            {
                decimal pickQty = details.FirstOrDefault().PickQty;
                decimal Qty = details.FirstOrDefault().Qty;
                decimal residueQtyf = Qty - pickQty;

                if (pickQty >= Qty)
                {
                    rfInfo.type = "FAIL";
                    rfInfo.message = "单据内配料数量已超出物料数量，请检查！";
                    return rfInfo;
                }
                if (intSplitQty > residueQtyf)
                {
                    rfInfo.type = "FAIL";
                    rfInfo.message = "扫描数量大于剩余配料数量，请检查！";
                    return rfInfo;
                }
            }
            //验证退料单的关联工单与领料单的管理工单是否一致
            WmsRackPackage_Extend moveHeaderInfo = repository.GetmoveHeaderInfo(cartonNo, orderNo);
            if (moveHeaderInfo == null)
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "扫描退料单工单与领料单关联工单不一致，请检查！";
                return rfInfo;
            }
            rfInfo.type = "PASS";
            rfInfo.message = "请扫描目标库位";
            return rfInfo;
        }


        /// <summary>
        /// 退料-扫描目标库位
        /// </summary>
        /// <param name="locate"></param>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public SetObjectDetail CheckReturnMaterialLocate(string locateName, string orderNo, string rackOrcartNo, string cartonNo, string SplitQty, string locate, string loginId)
        {
            SetObjectDetail rfInfo = new SetObjectDetail();//返回消息
            List<SysLocate> locateInfo = repository.GetLocateInfo(locate);
            if (locateInfo == null || locateInfo.Count == 0)
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "[" + locate + "]:库位不存在，请检查!";
                return rfInfo;
            }
            List<WmsRackPackage_Extend> rackPackageInfo = repository.GetrackPackageInfo(rackOrcartNo);
            if (locateName != locate)
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "扫描的库位与推荐库位不一致，请检查！";
                return rfInfo;
            }

            //已使用库容
            List<SysStock> s = repository.GetLocateCapacity(locateInfo[0].LocateId.ToString());
            if (locateInfo[0].LocateCapacity <= s[0].Qty)
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "[" + locate + "]:线边库已满，请检查!";
                return rfInfo;
            }

            //获取扫描的箱条码
            SysStock_Extend stockInfo = repository.GetCartonNoInfo2(cartonNo);

            WmsRackPackage_Extend rackPackageInfo2 = repository.GetpackageInfo(cartonNo);
            int intSplitQty = Convert.ToInt32(SplitQty);
            int locateId = locateInfo.FirstOrDefault().LocateId;
            string locateCode = locateInfo.FirstOrDefault().LocateName;
            int zoneId = locateInfo.FirstOrDefault().ZoneId;
            string zoneCode = locateInfo.FirstOrDefault().ZoneName;

            //获取单据中的物料信息
            List<WmsMoveDetail_Extend> detailInfo = repository.GetMoveDetailInfo(orderNo);
            List<WmsMoveDetail_Extend> wmsMoveDetails = detailInfo.Where(x => x.PartNo == stockInfo.PartNo).ToList();
            if (wmsMoveDetails.Count != 0)
            { 
            
            }
            //需要拆分的箱条码信息
            List<SysStock> MaterialInfo = repository.GetMaterialInfo(cartonNo);
            if (stockInfo.Qty == intSplitQty)
            {

                repository.UpdatePickingLocate(rackPackageInfo2, locateId, locateCode, rackOrcartNo, MaterialInfo, intSplitQty, loginId);
            }
            else
            {
                repository.UpdateReturnMaterialInfo(orderNo,wmsMoveDetails, stockInfo, locateId, locateCode, zoneId ,zoneCode, rackOrcartNo, MaterialInfo, intSplitQty, loginId, 1);
            }

            //更新拆分后数据
            stockInfo = repository.GetCartonNoInfo2(cartonNo);
            repository.UpdtePickingInfo(rackPackageInfo2, stockInfo, loginId, rackOrcartNo, loginId, rackOrcartNo, locateId, locateCode);



            List<WmsRackPackage_Extend> PackageInfo = repository.GetRackPackageInfo(rackOrcartNo);
            if (PackageInfo.Count > 0)
            {
                rfInfo.type = "PASS";
                rfInfo.message = "[" + cartonNo + "]:单据操作完成!";
                rfInfo.wmsObjectDetail = PackageInfo.ConvertAll(s => (object)s);
            }
            else
            {
                rfInfo.type = "PASS";
                rfInfo.message = "[" + cartonNo + "]:单据操作完成!";
            }
            return rfInfo;
        }



        /// <summary>
        /// (空)周转箱出入库-扫描周转箱
        /// </summary>
        /// <param name="locateName"></param>
        /// <param name="rackNo"></param>
        /// <param name="isOut"></param>
        /// <param name="loginId"></param>
        /// <returns></returns>
        public SetObjectDetail CheckStockRackNo(string locateName, string rackNo, string isOut, string loginId)
        {
            SetObjectDetail rfInfo = new SetObjectDetail();//返回消息
            int locateId = 0;
            int zoneId = 0;
            string zoneCode = "";
            string locateCode = "";

            //判断箱条码是否可用
            SysStock_Extend stockInfo = repository.GetCartonNoInfo2(rackNo);
            if (stockInfo == null)
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "[" + rackNo + "]:扫描的周转箱不存在!";
                return rfInfo;
            }
            else if (stockInfo.CartonType != 1) 
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "[" + rackNo + "]:扫描的条码不是周转箱!";
                return rfInfo;
            }

            //验证扫描的周转箱是否为空
            List<WmsRackPackage_Extend> rackPackageList = repository.GetCartonInfo(rackNo);
            if (rackPackageList.Count != 0)
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "请扫描空周转箱!";
                return rfInfo;
            }
            if (!string.IsNullOrEmpty(locateName))
            {
                //获取扫描的库位、库区
                SysLocate locateInfo = repository.GetLocateInfo(locateName).FirstOrDefault();
                locateId = locateInfo.LocateId;
                locateCode = locateInfo.LocateName;
                zoneId = locateInfo.ZoneId;
                zoneCode = locateInfo.ZoneName;
            }

            repository.UpdteStockRackNoInfo(stockInfo, loginId, rackNo, locateId, locateCode, zoneId, zoneCode);
            rfInfo.type = "PASS";
            rfInfo.message = "[" + rackNo + "]:操作完成!";
            return rfInfo;
        }
    }

}
